/*
 * Copyright Eduardo Aponte 2013
 * aponteeduardo@gmail.com
 */
#include <eyelink.h>
#include "mex.h"
#include "utils.h"


INT16 _main( UINT16 flag, INT16 lock )
{
    return eyelink_data_start( flag, lock); 
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    int f,l;
    
    /* Verify input arguments. */
    if( nrhs != 2 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    
    if ( isscalar( prhs[0] ) ){
        if (returnscalar( prhs[0], &f ) != 1 )
            mexErrMsgTxt("Complex data is not supported.");                             if ( f < 0 )
            mexErrMsgTxt("flag should be positive.");
    } else {
         mexErrMsgTxt("flag should be scalar.");
    } 
    
    if ( isscalar( prhs[1] ) ){
        if (returnscalar( prhs[1], &l ) != 1 )
            mexErrMsgTxt("Complex data is not supported.");                     
    } else {
         mexErrMsgTxt("lock should be scalar.");
    } 

    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
    *status = (double ) _main( (UINT16 ) f, (INT16 ) l );
        
    return;
}
